import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.Socket;
import java.net.UnknownHostException;

import com.acme.domain.bank.Bank;

public class BankClient implements Serializable {

	/**
	 * Available scenario:
	 * "BankClient add informationAboutClient"
	 * Example:
	 * BankClient add accounttype=c;balance=6100;overdraft=8500;name=Basil;gender=m;
	 */
	private static final long serialVersionUID = 1L;

	public static void main(String[] args) throws UnknownHostException,
			IOException, ClassNotFoundException {
		Socket serverSocket = new Socket("localhost", 2345);
		System.out.println("Connected with server.");

		ObjectOutputStream out = new ObjectOutputStream(
				serverSocket.getOutputStream());
		ObjectInputStream in = new ObjectInputStream(
				serverSocket.getInputStream());

		Bank bank = new Bank();
		System.out.println("Client ready...");
		do {
			out.writeObject(args);
			out.writeObject("OK");
			while (in.readObject().equals("Sending...")) {
				if (in.readObject() instanceof Bank) {
					bank = (Bank) in.readObject();
					System.out.println(bank);
					out.writeObject("bank is ok");
					break;
				}
			}
			System.out.println("Message from server was read successfully.");
			out.writeObject("end");
		} while (!(in.readObject().equals("end")));

		in.close();
		out.close();
		serverSocket.close();
	}

}
